# -*- coding: utf-8 -*-
import scrapy
from tutorial.items import DmozItem

class DmozSpiderSpider(scrapy.Spider):
    name = 'dmoz_spider'
    # allowed_domains = ['dmoz.org']
    start_urls = [
        'https://laravel-china.org/topics',
        'https://laravel-china.org/docs/laravel/5.6/configuration/1353/',
    ]

    def parse(self, response):
        # filename = response.url.split('/')[-2]+'.html'
        # with open('temp/'+filename, 'wb') as fp:
        #     fp.write(response.body)
        lis = response.xpath('//*[@id="wrap"]/div[2]/div[1]/div[2]/div[2]/div[1]/ul/li')
        for li in lis:
            item = DmozItem()
            item['title'] = li.xpath('/div[2]/div/a/text()').extract()
            item['link'] = li.xpath('/div[2]/div/a/@href').extract()
            item['desc'] = li.xpath('/a/div/span[1]/text()').extract()
            yield item